var express = require('express');
var router = express.Router();
const { login, salesLogin, getAdmins, updateState, getAdminsByUsername, addAdmins, deleteAdmins, getAdminsById, updateAdmins } = require('../service/adminService')

/* GET home page. */
//管理员登录
router.post('/login', async function (req, res, next) {
  const data = await login(req.body)
  res.send(data)
});
//销售员登录
router.post('/salesLogin', async function (req, res, next) {
  console.log(req.body);
  const data = await salesLogin(req.body)
  res.send(data)
});
//  获取管理员数据
router.get('/getAdmins', async function (req, res, next) {
  const params = req.query;
  const data = await getAdmins(params);
  res.send(data);
})
// 修改管理员权限
router.post('/updateState', async function (req, res, next) {
  const data = await updateState(req.body)
  res.send(data)
});
router.post('/getAdminsByUsername', async function (req, res, next) {
  const data = await getAdminsByUsername(req.body);
  res.send(data);
});
// 添加管理员
router.post('/addAdmins', async function (req, res, next) {
  const data = await addAdmins(req.body);
  res.send(data);
});
// 删除管理员
router.post('/deleteAdmins', async function (req, res, next) {
  const data = await deleteAdmins(req.body);
  res.send(data);
})
// 根据id获取管理员
router.get('/getAdminsById', async function (req, res, next) {
  const data = await getAdminsById(req.query);
  res.send(data);
})
// 修改管理员信息
router.post('/modifyAdmins', async function (req, res, next) {
  const data = await updateAdmins(req.body);
  res.send(data);
})


module.exports = router;
